home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-27 | 4.6 KB | 156 lines | [TEXT/MPS ] |
- // Nothing.cp
- // Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.
-
- /*
- This is a very small sample application which can save files on disk and can
- print.
-
- The application's windows each contain the word 'MacApp', in large type, and
- are framed by a large gray border.
-
- Documents can be saved on disk and later reopened, but the only
- document-specific information saved in the disk file is the Print information,
- which means that if you set print specifications using the Page Setup dialog
- for a document, and then save the document (using Save As or Save a Copy),
- those specifications are saved on disk, and when you reopen the document
- you will find those same print specifications holding for the document.
-
-
- All applications that create views procedurally need to reimplement at least three
- methods:
-
- TApplication.DoMakeDocument -- Launches the appropriate type of Document object
- TDocument.DoMakeViews -- Launches the appropriate type of View and window objects
- TView.Draw -- Draws the contents of a view
-
- This application, however, consists of the reimplementation of only one method -
- TView.Draw. This is possible since the view is created from templates; MacApp
- supplies the default 'view' resource. So in a sense this application is the smallest
- possible MacApp application.
- */
-
- // {$MC68020-} // The main program must be universal code
- // {$MC68881-}
-
- //-------------------------------------------------------------------------------------
- // INCLUDES
-
- // • MacApp
- #include <UMacApp.h>
- // • Building Blocks
- #include <UPrinting.h>
- // • Implementation Use
- #include <Fonts.h>
-
- //-------------------------------------------------------------------------------------
- // CONSTANTS
-
- const OSType kSignature = 'SS01'; // Application signature
- const OSType kFileType = 'SF01'; // File-type code used for document files created by this application
-
- //-------------------------------------------------------------------------------------
- // TYPES
-
- class TNothingApplication : public TApplication {
- public:
- // Initializes the application and globals.
- virtual pascal void INothingApplication(OSType itsMainFileType);
- };
-
- class TDefaultView : public TView {
- public:
- // Draws the view seen in the window. Every nonblank view MUST override this method.
- virtual pascal void Draw(Rect *area);
- };
-
- //-------------------------------------------------------------------------------------
-
- pascal void TNothingApplication::INothingApplication(OSType itsMainFileType)
- {
- IApplication(itsMainFileType);
-
- // So my view will be substituted when MacApp® creates the "default view"
- RegisterStdType("\pTDefaultView", 'dflt');
-
- // So the linker doesn't dead strip class info
- if (gDeadStripSuppression)
- {
- TDefaultView *aDfltView;
- aDfltView = new TDefaultView;
- }
- }
-
- // ---------------------------------------------------------------------------------------
-
- // NOTE: we don't define a name for the argument here, so CFront won't complain about
- // the argument being unused!
- pascal void TDefaultView::Draw(Rect *)
- {
- Rect itsQDExtent;
-
- PenNormal();
- PenSize(10, 10);
- PenPat(qd.dkGray);
-
- // We know its extent always fits in QuickDraw coordinates.
- GetQDExtent(&itsQDExtent);
- // Draw a dark gray frame
- FrameRect(&itsQDExtent);
-
- // Set font and size for subsequent display in the window
- TextFont(applFont);
- TextSize(72);
-
- MoveTo(45, 90);
- // Draw the word 'MacApp®' in large type.
- DrawString("\pMacApp®");
- // Restore the pen state.
- PenNormal();
- }
-
- // ---------------------------------------------------------------------------------------
- // T H E M A I N P R O G R A M
-
- // GLOBALS
- TNothingApplication *gNothingApplication; // The application object
-
- void main()
- {
- // Essential toolbox and utilities initialization
- InitToolBox();
-
- // Make sure we can run
- if (ValidateConfiguration(&gConfiguration))
- {
- // We made it! Continue with remainder of initialization
-
- // Initialize MacApp; 8 calls to MoreMasters
- InitUMacApp(8);
-
- // ------------------------------------------------------
- // If you are going to use streams for debugging IO then:
- // #include <stdio.h>
- // #include <iostream.h>
- // and execute the following line since MacApp's debug output is essentialy "printf"s
-
- // cout.sync_with_stdio();
-
- InitUPrinting();
-
- // Allocate a new TNothingApplication object, and check for errors
- gNothingApplication = new TNothingApplication;
- FailNIL(gNothingApplication);
- // Initialize the application object
- gNothingApplication->INothingApplication(kFileType);
-
- // Run the application. When it's done, exit.
-
- gNothingApplication->Run();
- }
- else
- {
- StdAlert(phUnsupportedConfiguration);
- }
-
- }
-